<?php	
class honor{
	function getFileList( &$file_id  ){
		global $dbs ,$user ,$encrypt ;
		
		$sql = 'SELECT * FROM `'.DB_PRE.'file_honor` WHERE `file_id` = '. $file_id .' ORDER BY `id` DESC ' ;
		
		$honors = $dbs -> select($sql);
			
		$html = '<font class="honorList">';
		foreach( $honors as $honor){			
			$sql = 'SELECT * FROM `'.DB_PRE.'task` WHERE `id` = '. $honor['task_id'] .' limit 0,1' ;
			$task = $dbs -> select($sql);
			$task = $task[0];			
			$id 			= $encrypt -> code( $honor['id']);
			$task_id_code	= $encrypt -> code( $honor['task_id'] ) ;
			$html .= '<b>
			<a target="_blank" href="'.WEB_ROOT_PATH.'?option=task&id='.$task_id_code .'" class="'. $honor['cssClass'] .'">'. $honor['name'] .'</a>';
			if( ($user -> id() == $task['user_id'] && $user -> powder() >= 5) || $user -> powder() >= 9 )
				$html .= '<a href="'.WEB_ROOT_PATH.'?option=taskManageAction&type=action&do=delHonor&honor_id='. $id .'" class="del"></a>';			
			$html .= '</b>';
		}
		$html .= '</font>';
		if( count( $honors ) == 0 )
			$html = '';
		return $html;
	}
	
	function getUserList(&$user_id, &$task_id){
		
	}
	
	function add(&$task_id , &$file_id, &$name ,&$cssClass ){
		global $dbs , $dataType ;
		$sql = 'SELECT * FROM `'.DB_PRE.'file_honor` WHERE `task_id` = '. $task_id .' and `file_id` ='. $file_id .' and `name` = "'. $name  .'" ' ;
		$lists = $dbs -> select($sql);		
		
		if( count($lists) == 0 ){			
			
			$sql = 'SELECT * FROM `'.DB_PRE.'file` WHERE `id` = '. $file_id ;
			$file = $dbs -> select($sql);
			$file = $file[0];
		
			$array['task_id'] 	= $task_id ;
			$array['file_id'] 	= $file_id ;			
			$array['name'] 		= $name ;
			$array['user_id'] 	= $file['user_id'] ;
			$array['cssClass'] 	= $cssClass ;
			$array['created'] 	= date('Y-m-d H:i:s',time()) ;
			$array['ip']		= ip() ;
			
			$dbs -> insert( DB_PRE .'file_honor' , $array );
			exit('<div class="ok">已经成功增加</div>');		
		}else{
			exit('<div class="error">此荣誉已经存在,无需新增.</div>');
		}
		
	}
	
	function del( &$honor_id ){
		global $dbs ,$user  ;
		$sql = 'SELECT * FROM `'.DB_PRE.'file_honor` WHERE `id` = '.(int)$honor_id;
		$honors = $dbs -> select($sql);
		$honors = $honors[0];
		if( count($honors) == 0  )
			exit('{"status":"error","msg":"名誉不存在."}');
		
		if( ($user -> id() != $honors['user_id']) && $user -> powder() < 9 )
			exit('{"status":"error","msg":"您没有权限改动."}');
		
		$dbs -> delete( DB_PRE .'file_honor' ,' `id` = '.(int)$honor_id );
		exit('{"status":"success","msg":"'.lang_delete_success.'."}');
		
	}
	
}
?>